<template class='body'>
  <van-row class="main-menu">
    <div class="waiquanbox">
      <van-nav-bar left-text="返回首页" title="待办" @click-left="doBack" />
      <div class="neiquanbox">
        <div class="contentLeft">
        </div>
        <div class="contentRitht">
          <div class="taptitle">待办事项</div>
          <el-tabs v-model="activeName" @tab-click="handleClick">
            <el-tab-pane
              :label="'未办' + '（' + tableDatatotal.length + '）'"
              name="quanbu"
            >
              <div class="tabheader">
                <div class="demo-input-suffix">
                  查询：
                  <el-input
                    placeholder="请输入内容"
                    v-model="searinput"
                    class="searinput input-with-select"
                    style="margin-bottom:10px;"
                  >
                    <el-button
                      class="iconsearch"
                      slot="append"
                      type="primary"
                      icon="el-icon-search"
                      @click="searchCont"
                    ></el-button>
                  </el-input>
                  <!-- <el-button>
                    <router-link to="/dealtwith/bigscreen/">数据看板</router-link>
                  </el-button> -->
                  <!-- <el-button class="daoru" @click="chuanjianp">测试创建批次</el-button> -->
                </div>
                <div class="tablecontent" v-if="!showtableDone">
                  <el-table
                    stripe
                    :data="
                      tableData.slice(
                        (currentPage - 1) * pagesize,
                        currentPage * pagesize
                      )
                    "
                    empty-text="暂无数据"
                    v-loading="loading"
                    style="width: 100%;margin-top:30px;"
                  >
                    <el-table-column label="标题">
                      <template slot-scope="scope">
                        <i :class="[scope.row.term==1 || scope.row.term==2?'el-icon-s-opportunity':'',scope.row.term==0?'':[scope.row.term==1?'iconyellow':'iconred']]"></i>
                        <el-tooltip effect="dark" :content="scope.row.title" placement="top"> 
                          <a style="cursor: pointer;" @click="getupInformation(scope.row.dbstatus,scope.row.score_type,scope.row.type,scope.row.check_type,scope.row.updatetime,scope.row.id,scope.row.sscm,scope.row.bmmc)">{{scope.row.type == '1' ? '（整改）' : '（评分）'}}{{scope.row.title}}</a> 
                        </el-tooltip> 
                      </template>
                    </el-table-column>
                    <el-table-column prop="bmmc" label="部门名称" width="300">
                      <!-- <template slot-scope="scope" v-if="scope.row.type == 0"> 
                        {{scope.row.bmmc}}
                      </template> -->
                    </el-table-column>
                    <el-table-column prop="wtfxr" label="问题发现人" width="100">
                      <!-- <template slot-scope="scope" v-if="scope.row.type == 0">
                        {{scope.row.wtfxr}}
                      </template> -->
                    </el-table-column>
                    <el-table-column prop="wtfxsj" label="提单时间" width="100">
                    </el-table-column>
                    <!-- <el-table-column prop="dbman" label="待办人">
                    </el-table-column> -->
                  </el-table>
                  <div class="pagefanye right">
                    <el-pagination
                      @size-change="handleSizeChangeWenti"
                      @current-change="handleCurrentChangeWenti"
                      :current-page="currentPage" 
                      :page-sizes="[5, 10, 20, 40]"
                      :page-size="pagesize"
                      layout="total, sizes, prev, pager, next, jumper"
                      :total="tableData.length"
                    >
                    </el-pagination>
                  </div>
                </div>
                <div class="tablecontent" v-if="showtableDone">
                  <el-table
                    @row-click="doShowDetail"
                    stripe
                    :data="mytableDone.slice(
                        (currentPageDone - 1) * pageSizeDone,
                        currentPageDone * pageSizeDone
                      )"
                    empty-text="暂无数据"
                    v-loading="loading"
                    style="width: 100%;margin-top:30px;"
                  >
                    <el-table-column prop="title" label="标题" min-width="400">
                      <template slot-scope="scope">
                        <el-tooltip effect="dark" :content="scope.row.title" placement="top"> 
                          <a>{{scope.row.opType == '1' ? '（整改）' : '（评分）'}}{{scope.row.title}}</a>
                        </el-tooltip>
                      </template>
                    </el-table-column>
                    <el-table-column prop="bmmc" label="部门名称">
                      <!-- <template slot-scope="scope" v-if="scope.row.type == 0">
                        {{scope.row.bmmc}}
                      </template> -->
                    </el-table-column>
                    <el-table-column label="操作人">
                       <template slot-scope="scope">
                          <a>{{scope.row.userName == '' ? userName : scope.row.userName}}</a>
                      </template>
                    </el-table-column>
                     <el-table-column prop="createTime" label="操作时间">
                    </el-table-column>
                  </el-table>
                  <div class="pagefanye right">
                    <el-pagination
                      @size-change="handleSizeChangeDone"
                      @current-change="handleCurrentChangeDone"
                      :current-page="currentPageDone"
                      :page-sizes="[5, 10, 20, 40]"
                      :page-size="pageSizeDone"
                      layout="total, sizes, prev, pager, next, jumper"
                      :total="mytableDone.length"
                    >
                    </el-pagination>
                  </div>
                </div>
              </div>
            </el-tab-pane>
            <el-tab-pane :label="'未读' + '（' + tabelDataread + '）'" name="weidu">未读</el-tab-pane>
            <el-tab-pane :label="'超期' + '（' + tabelDataterm + '）'" name="daoqi">超期</el-tab-pane>
            <el-tab-pane name="wodefaqi">    
              <span slot="label">
                <el-dropdown placement="bottom">
                  <span>我的发起</span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item>
                      <span @click="launchRectification">整改</span>
                    </el-dropdown-item>
                    <el-dropdown-item>
                      <span @click="launchEvaluation">考评</span>
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </span>
            </el-tab-pane>
            <el-tab-pane name="wodejingban">
              <span slot="label">
                <el-dropdown placement="bottom">
                  <span>我的经办</span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item>
                      <span @click="handlingRectification">整改</span>
                    </el-dropdown-item>
                    <el-dropdown-item>
                      <span @click="handlingEvaluation">考评</span>
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </span>
            </el-tab-pane>
          </el-tabs>
        </div>

      </div>
      <!-- 整改 -->
      <van-popup
        v-model="showPageRectifyDetail"
        position="right"
        get-container="body"
        style="width: 100%; height: 100%; background-color: #F9F9F9">
        <dealt-with-detail v-if="showPageRectifyDetail" :rectify="selectedRectify" @onCancel="showPageRectifyDetail = false" @onConfirm="doConfirm"/>
      </van-popup>
      <!-- 评分 -->
      <van-popup
        v-model="showPageGradeDetail"
        position="right"
        get-container="body"
        style="width: 100%; height: 100%; background-color: #F9F9F9">
        <dealt-with-pfdetail v-if="showPageGradeDetail" :grade="selectedGrade" @onCancel="showPageGradeDetail = false" @onConfirm="doConfirm"/>
      </van-popup>
      <!-- 加分 -->
      <van-popup
        v-model="showPageRaiseDetail"
        position="right"
        get-container="body"
        style="width: 100%; height: 100%; background-color: #F9F9F9">
        <dealt-with-sub v-if="showPageRaiseDetail" :apply="selectApply" v-on:onCancel="showPageRaiseDetail = false" @onConfirm="doConfirm"/>
      </van-popup>
      <fotter-view></fotter-view>
    </div>
  </van-row>
</template>



<script>
import DealtWithDetail from '@/views/dealtwith/DealtWithDetail' //整改详情
import DealtWithPfdetail from '@/views/dealtwith/DealtWithPfdetail' //评分详情
import DealtWithSub from '@/views/dealtwith/DealtWithSub' //加分详情
/* 交互api */
import {
  openShouPinfendw,
  openShouPinfen,
  getselectList,
  //selectHaveList,
  createBatch,//创建批次
  selectScoreupdate,
  launchRectificationapi,  //我的发起整改
  launchEvaluation,   //我的发起考评
  handlingRectification,   //我的已办整改
  handlingEvaluation,  //我的已办考评
  QuestionDetails  //待办详情
} from "../../api/dealtwith";
import { Loading } from "element-ui";
export default {
  components: { DealtWithDetail,DealtWithPfdetail,DealtWithSub },
  data() {
    return {
      userid:'',//用户id
      userName:'',//用户名
      activeName: "quanbu",
      loading: false, //加载
      searinput: "",
      currentPage: 1, //初始页
      pagesize: 10, // 每页的数据
      pageSizeDone: 10, // 每页的数据
      assessTypezero: 0, //评分列表 0公司
      assessTypeone: 1, //评分列表 1單位
      department_path: "", //部门
      tableDatatotal:[],//存入全部 未读 超期的数量
      showPageRectifyDetail: false, //整改详情
      showPageGradeDetail: false,  //评分详情
      showPageRaiseDetail: false,  //加分详情
      tableData: [
        {
          title: "啊打发撒旦",
          bmmc: "公司本部/基建部",
          wtfxr: "上海市普陀区金沙江路 1518 弄",
          wtfxsj: "2016-05-02",
          dbman: "小红111",
          dbstatus:0
        },
        {
          title: "阿斯蒂芬",
          bmmc: "公司本部/安全监管部（应急指挥中心）",
          wtfxr: "上海市普陀区金沙江路 1518 弄",
          wtfxsj: "2016-05-02",
          dbman: "小红222",
          dbstatus:0
        },
        {
          title: "委任他为和",
          bmmc: "广州局/安全监管部",
          wtfxr: "上海市普陀区金沙江路 1518 弄",
          wtfxsj: "2016-05-02",
          dbman: "小红333",
          dbstatus:1
        },
      ],
      mytableDone:[],
      tabelDataread:0,//未读
      tabelDataterm:0,//超期
      tabelDataDone:0,//已办
      showtableDone:false,//隐藏显示待办列表
      currentPageall: 4,
      ifgsdw:'', //是否是公司还是单位
      currentPage: 1,   // 当前页码
      currentPageDone:1,
      totalDone: 0,   // 总条目数
      pagenumDone: 1, // 当前页码
      pageSizeDone: 5, // 每页显示条数
      zgcondition: {
        dbman: this.$store.state.authInfo.user.userid,
        title:'',
        opType:1,    // 查询参数
      },
      kpcondition: {
        dbman: this.$store.state.authInfo.user.userid,
        title:'',
        opType:0,    // 查询参数
      }
    };
  },
  created() {
    //获取用户人userid
    this.userid = this.$store.state.authInfo.user.userid
    this.userName = this.$store.state.authInfo.user.username
    console.log(this.userName)
    this.getList()
  },
  mounted() {
    //获取部门
    // this.$store.commit('authInfo/setCurrentDept', '公司本部->基建部')
    this.department_path = this.$store.state.authInfo.user.rectify[0].department_path
    console.log(this.$store.state.authInfo.user.rectify[0].department_path)
    console.log(this.department_name);
  },
  methods: {
    doShowDetail (row,index,e) {
      console.log(row)
      //       showPageRectifyDetail: false, //整改详情
      // showPageGradeDetail: false,  //评分详情
      // showPageRaiseDetail: false,  //加分详情

      QuestionDetails({ opType:row.opType,checkType:row.checkType,objType:row.objType,problemId:row.problemId })
      .then((res) => {
        console.log(res);
        if(row.objType == ''){
          this.showPageRectifyDetail = true //整改详情
          this.selectedRectify = res.data.retData
        }else if(row.objType == '0'){
          this.showPageGradeDetail= true  //评分详情
          this.selectedGrade = res.data.retData
        }else if(row.objType == '1'){
          this.showPageRaiseDetail= true  //加分详情
          this.selectApply = res.data.retData
        }
      })
      .catch((err) => {
        this.loading = false;
        console.log("报错！！！！！！！！！！！");
      });
    },
    doConfirm () {
      this.showPageRectifyDetail = false
    },
    //创建批次
    chuanjianp(){
      createBatch()
      .then((res) => {
        console.log(res)
        
      })
      .catch((err) => {
        console.log("报错！！！！！！！！！！！");
      });
    },
    //获取对应环节跳转
    getupInformation(dbstatus,score_type,type,check_type,updatetime,id,sscm,bmmc){

      if((dbstatus == 0 || dbstatus == 8) && score_type == 0 && type == 0){ //考评列表（为考评
        this.$router.push({path:'/grade/' + check_type  + '/' + this.$vo.OperateType.GRADE,query:{bmmc:bmmc}})
      }else if(dbstatus == 1 && score_type == 0 && type == 0){ //评分审核
        this.$router.push({path:'/resume/' + check_type  + '/' + this.$vo.OperateType.CHECK,query:{bmmc:bmmc}})
      }else if(dbstatus == 2 && score_type == 0 && type == 0){ //考评查询
        this.$router.push({path:'/grade/' + check_type  + '/' + this.$vo.OperateType.FEEDBACK,query:{bmmc:bmmc}})
      }else if(dbstatus == 3 && score_type == 0 && type == 0){ //反馈审核
        this.$router.push({path:'/grade/' + check_type  + '/' + this.$vo.OperateType.APPROVE,query:{bmmc:bmmc}})
      }else if(dbstatus == 4 && score_type == 0 && type == 0){ //反馈复核
        this.$router.push({path:'/grade/' + check_type  + '/' + this.$vo.OperateType.RECHECK,query:{bmmc:bmmc}})
      }else if(dbstatus == 5 && score_type == 0 && type == 0){ //最终审核
        this.$router.push({path:'/grade/' + check_type  + '/' + this.$vo.OperateType.REVIEW,query:{bmmc:bmmc}})
      }else if(dbstatus == 6 && score_type == 0 && type == 0){ //返回考评列表（为考评）
        this.$router.push({path:'/grade/' + check_type  + '/' + this.$vo.OperateType.GRADE,query:{bmmc:bmmc}})
      }else if(dbstatus == 0 && score_type == 1 && type == 0){ //加分审核
        this.$router.push({path:'/raise/' + check_type  + '/' + this.$vo.OperateType.CHECK,query:{bmmc:bmmc}})
      }else if(dbstatus == 1 && score_type == 1 && type == 0){ //加分复核
        this.$router.push({path:'/raise/' + check_type  + '/' + this.$vo.OperateType.RECHECK})
      }else if((dbstatus == 2||dbstatus == 3) && score_type == 1 && type == 0){ //最终审核
        this.$router.push({path:'/raise/' + check_type  + '/' + this.$vo.OperateType.REVIEW})
      }else if(dbstatus == 4 && score_type == 1 && type == 0){ //加分申请
        this.$router.push({path:'/raise/' + check_type  + '/' + this.$vo.OperateType.APPLY}) //!============================================!
      }else if(dbstatus == 0 && type == 1){ //指定整改责任部门
        this.$router.push({path:'/rectify/list/' + check_type + '/' + this.$vo.RectStep.FIND,query:{sscm:sscm,bmmc:bmmc}})
      }else if(dbstatus == 1 && type == 1){ //整改措施制定
        this.$router.push({path:'/rectify/list/' + check_type + '/' + this.$vo.RectStep.PLAN,query:{sscm:sscm,bmmc:bmmc}})
      }else if((dbstatus == 2 || dbstatus == 5 || dbstatus == 6 ) && type == 1){ //整改措施审核
        this.$router.push({path:'/rectify/list/' + check_type + '/' + this.$vo.RectStep.APPR,query:{sscm:sscm,dbstatus:dbstatus,bmmc:bmmc}})
      }else if((dbstatus == 3 || dbstatus == 7) && type == 1){ //整改措施落实
        this.$router.push({path:'/rectify/list/' + check_type + '/' + this.$vo.RectStep.EXEC,query:{sscm:sscm,dbstatus:dbstatus,bmmc:bmmc}})
      }else if((dbstatus == 4 || dbstatus == 8 || dbstatus == 9 ) && type == 1){ //整改成果验收
        this.$router.push({path:'/rectify/list/' + check_type + '/' + this.$vo.RectStep.ACCE,query:{sscm:sscm,dbstatus:dbstatus,bmmc:bmmc}})
      }
      //改变未读状态
      if(updatetime == null){
        this.choseupdatetime(id)
      }

    },
    //查询
    searchCont(){
      this.loading = true;
      getselectList({ dbman: this.userid,isRead :'',term:'',title:this.searinput })
      .then((res) => {
        this.loading = false;
        this.tableData = res.data.retData.list;
        if (res.data.retData.list.length == 0) {
            this.$message({
              type: "warning",
              message: "暂无内容",
            });
          }else{
            this.$message({
              type: "success",
              message: "查询成功",
            });
          }
      })
      .catch((err) => {
        this.loading = false;
        console.log("报错！！！！！！！！！！！");
      });
    },
    //获取列表
    getList(){
      this.loading = true;
      getselectList({ dbman: this.userid,isRead :'',term:'',title:'' })
      .then((res) => {
        this.loading = false;
        console.log(res);
        this.tableData = res.data.retData.list;
        this.tableDatatotal = res.data.retData.list //总数数量
        this.tabelDataread = res.data.retData.read //未读数量
        this.tabelDataterm = res.data.retData.term //超期数量
        //this.selectHaveList()
      })
      .catch((err) => {
        this.loading = false;
        console.log("报错！！！！！！！！！！！");
      });

    },
    // selectHaveList(){
    //   selectHaveList({ dbman: this.userid,title:'' })
    //   .then((res) => {
    //     console.log(res);
    //     this.mytableDone = res.data.retData 
    //     this.tabelDataDone = res.data.retData.length //总数数量
        
    //   })
    //   .catch((err) => {
    //     this.loading = false;
    //     console.log("报错！！！！！！！！！！！");
    //   });
    // },
    //改变查看状态
    choseupdatetime(id){
      console.log(id)
      selectScoreupdate({id :id })
        .then((res) => {
        console.log(res);
      })
      .catch((err) => {
        console.log("报错！！！！！！！！！！！");
      });
    },
    shoupinfen() {
      openShouPinfen() //请求临时列表数据
        .then((res) => {
          console.log(res);
          if (res.data.retCode == "200") {
            this.$message({
              type: "error",
              message: "公司评分手动开启失败，已有启动的公司评分批次",
            });
          }
          if (res.data.retCode == "400") {
            this.$message({
              type: "success",
              message: "公司评分手动开启成功",
            });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    shoupinfendw() {
      openShouPinfendw() //请求临时列表数据
        .then((res) => {
          console.log(res);
          if (res.data.retCode == "200") {
            this.$message({
              type: "error",
              message: "单位评分手动开启失败，已有启动的单位评分批次",
            });
          }
          if (res.data.retCode == "400") {
            this.$message({
              type: "success",
              message: "单位评分手动开启成功",
            });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //标签页
    handleClick(tab, event) {
      console.log(tab.index, event);
      console.log(this.pageSizeDone)
      this.showtableDone = false

      //根据index切换页面内容
      if(tab.index == 0){
       this.getList()
      }else if(tab.index == 1){
        this.loading = true;
        //未读
        getselectList({ dbman:this.userid,isRead :"1",term:'',title:'' })
          .then((res) => {
            this.loading = false;
            console.log(res);
            this.tableData = res.data.retData.list;
          })
        .catch((err) => {
          this.loading = false;
          console.log("报错！！！！！！！！！！！");
        });
      }else if(tab.index == 2){
        console.log(this.tabelDataread)
        this.loading = true;
        //到期
        getselectList({ dbman: this.userid,isRead :"",term:'2',title:'' })
          .then((res) => {
            this.loading = false;
            console.log(res);
            this.tableData = res.data.retData.list;
          })
        .catch((err) => {
          this.loading = false;
          console.log("报错！！！！！！！！！！！");
        });
      }else if(tab.index >2){
        this.showtableDone = true
      }
    },
    //我的发起整改
    launchRectification(){
      this.showtableDone = true
      this.activeName = 'wodefaqi'
      this.loading = true;
      launchRectificationapi(this.zgcondition)
        .then((res) => {
          this.loading = false;
          console.log(res);
          this.mytableDone = res.data.retData 
        })
      .catch((err) => {
        this.loading = false;
        console.log("报错！！！！！！！！！！！");
      });
    },

    //我的发起考评
    launchEvaluation(){
      this.showtableDone = true
      this.activeName = 'wodefaqi'
      this.loading = true;
      launchEvaluation(this.kpcondition)
        .then((res) => {
          this.loading = false;
          console.log(res);
          this.mytableDone = res.data.retData 
        })
      .catch((err) => {
        this.loading = false;
        console.log("报错！！！！！！！！！！！");
      });
    },
    
    //我的经办整改
     handlingRectification(){
      this.showtableDone = true
      this.activeName = 'wodejingban'
      this.loading = true;
      handlingRectification(this.zgcondition)
        .then((res) => {
          this.loading = false;
          console.log(res);
          this.mytableDone = res.data.retData 
        })
      .catch((err) => {
        this.loading = false;
        console.log("报错！！！！！！！！！！！");
      });
    },
    //我的经办评分
     handlingEvaluation(){
      this.showtableDone = true
      this.activeName = 'wodejingban'
      this.loading = true;
      handlingEvaluation(this.kpcondition)
        .then((res) => {
          this.loading = false;
          console.log(res);
          this.mytableDone = res.data.retData 
        })
      .catch((err) => {
        this.loading = false;
        console.log("报错！！！！！！！！！！！");
      });
    },
    rowClick(){
      console.log('222222')
    },
    //待办
    handleSizeChangeWenti(val) {
      this.pagesize = val;
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChangeWenti(val) {
      this.currentPage = val;
      console.log(`当前页: ${val}`);
    },
    //我得已办
    handleSizeChangeDone(val) {
      this.pageSizeDone = val;
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChangeDone(val) {
      this.currentPageDone = val;
      console.log(`当前页: ${val}`);
    },
    goPage(url) {
      window.open(url, "_blank"); // 新窗口打开外链接
    },
    doBack() {
      //this.$router.back();
        //var clearFlag="http://twentyfive.365kaifa.com:888/?flag=1&code=BAOwLIpkFga17vcJ6yKdfT0hpchrACpRd1olkWl9tI4&state=STATE#/dealtwith/index"; 
      //this.$router.push({ path: "/" });    
      if(window.document.location.href.indexOf('flag=1') != -1){
        if(window.document.location.href.slice(0,20).indexOf("http://twentyfive") != -1){
          window.location.href = 'http://twentyfive.365kaifa.com:888/'
        }else{
          window.location.href = 'https://app.ehv.csg.cn:41888/aj/'
        }
      }else{
        this.$router.push({ path: "/" });
      }
    },
  },
};
</script>

<style scoped lang="less">
body {
  background: #ccc;
}
a {
  color: #606266;
}
.right {
  float: right;
}
.iconyellow {
  color: #e2bd06;
}
.iconred {
  color: red;
}

.taptitle {
  font-size: 18px;
  padding: 10px 0;
  font-weight: bold;
}

.el-tabs__header {
  padding: 30px;
}
.iconsearch {
  color: #409eff !important;
}
.searinput {
  width: 250px;
}
.daoru {
  margin-left: 10px;
  margin-bottom: 10px;
}
.pagefanye {
  margin-top: 10px;
}
.searinputshu {
  width: 150px;
}
.inputbox {
  margin-right: 20px;
  display: inline-block;
  margin-top: 20px;
}
.el-tabs__content #pane-quanbu{
display: block !important;;
}
.el-tabs__content #pane-weidu,.el-tabs__content #pane-daoqi,.el-tabs__content #pane-wodeyiban{
display: none !important;;
}
/deep/.cell {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
  /deep/.el-pagination {
      white-space: normal;
  }
.el-tabs__item.is-active .el-dropdown{
      color: #409EFF;
}
.el-dropdown {
    font-weight: 500;
    color: #303133;
}
</style>
